/*
 * Copyright (c) 2017,安徽皖通科技股份有限公司 All rights reserved.
 */

package com.wttech.dzzf.process.service.correct;

import com.wttech.dzzf.process.dao.DataInitilizingDao;
import com.wttech.dzzf.process.model.JgTemp;
import com.wttech.dzzf.process.model.Temp;
import com.wttech.dzzf.process.service.errordata.CorrectErrorUserInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author MaShibo
 * @date 2017/12/14.
 */
@Service
public class CorrectErrorOrgInfos {

	private static final Logger LOGGER = LoggerFactory.getLogger(CorrectErrorUserInfoService.class);

	@Resource(name = "jdbcTemplate")
	private JdbcTemplate testJdbcTemplate;

	@Resource
	private DataInitilizingDao dataInitilizingDao;

	private void process() {
		final String sql = "SELECT * FROM BS_JGTEMP";
		List<JgTemp> temps = testJdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(JgTemp.class));
		temps.forEach(temp -> {
			LOGGER.info("正在更新CODE：{}", temp.getCode());
			dataInitilizingDao.updateOrg(temp);
		});
	}

	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		CorrectErrorOrgInfos service = context.getBean(CorrectErrorOrgInfos.class);
		service.process();
	}
}
